package com.moon.interface_api.utils;

import com.alibaba.druid.support.json.JSONUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SensitiveUtil {

	public static String doBusiz(Object obj) {
		try {
			return doChange(JSONUtils.toJSONString(obj));
		} catch (Throwable t) {
			return obj.toString();
		}
	}

	private static String doChange(String message) {
		Pattern p = Pattern.compile("\\d{11,}");
		Matcher m = p.matcher(message);
		while (m.find()) {
			String ss = m.group();
			ss = ss.substring(0, 4) + "****" + ss.substring(ss.length() - 4, ss.length());
			message = message.replace(m.group(), ss);
		}
		return message;
	}

}
